package luogu;

import java.util.Scanner;

public class P5734 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        for (int i = 0; i < n; i++) {
            int m = sc.nextInt();
            if (m == 1){
                String a = sc.next();
                String res = s + a;
                System.out.println(res);
                s = res;
                continue;
            }
            if (m == 2){
                int st = sc.nextInt();
                int end = sc.nextInt() + st;
                String res = s.substring(st, end);
                System.out.println(res);
                s = res;
                continue;
            }
            if (m == 3){
                int index = sc.nextInt();
                String a = sc.next();
                String res = s.substring(0, index) + a + s.substring(index);
                System.out.println(res);
                s = res;
                continue;
            }
            if (m == 4){
                String h = sc.next();
                int res = s.indexOf(h);
                System.out.println(res);
            }
        }
    }
}
